﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DuAnNH.Fd_class;

namespace DuAnNH.Fd_class
{
    class Cls_HoaDon
    {
        public static DataTable Tke_Ngay(string ngay)
        {
            try
            {
                string sql = "SELECT * from HoaDon where ThoiGianLap='" + ngay + "'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        //public static bool Tke_Ngay(DateTime ngay)
        //{
        //    try
        //    {
        //        string str = string.Format("SELECT * from HoaDon where day(ThoiGianLap)='{0}",ngay);
        //        SqlCommand com = new SqlCommand(str, Coso.con);
        //        com.ExecuteNonQuery();
        //        return true;
        //    }
        //    catch
        //    {
        //        return false;
        //    }
        //}
        public static DataTable Tke_thang(string thang,string nam)
        {
            try
            {
                string sql = "SELECT * from HoaDon where Month(ThoiGianLap)='" + thang + "' and Year(ThoiGianLap)='"+nam+"'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static DataTable Tke_khoangngay(string daybegin, string dayend)
        {
            try
            {
                string sql = "SELECT * from HoaDon where ThoiGianLap>='" + daybegin + "' and ThoiGianLap<='" + dayend + "'";
                SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
                DataTable tb = new DataTable();
                adap.Fill(tb);
                return tb;
            }
            catch
            {
                return null;
            }
        }
        public static bool Xoa_Tk_hd_ngay(string ngay)
        {
            try
            {
                string str = string.Format("DELETE FROM HoaDon where ThoiGianLap='{0}'" ,ngay);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Xoa_Tk_cthd_ngay(string ngay)
        {
            try
            {
                string str = string.Format("DELETE FROM ChiTietHoaDon where NgayTT='{0}'", ngay);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Xoa_Tk_cthd_thang(string thang,string nam)
        {
            try
            {
                string str = string.Format("DELETE FROM ChiTietHoaDon where Month(NgayTT)='{0}' and Year(NgayTT)={1}",thang,nam);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Xoa_Tk_hd_thang(string thang, string nam)
        {
            try
            {
                string str = string.Format("DELETE FROM HoaDon where Month(ThoiGianLap)='{0}' and Year(ThoiGianLap)={1}", thang, nam);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Xoa_Tk_hd_khoangngay(string daybegin, string dayend)
        {
            try
            {
                string str = string.Format("DELETE FROM HoaDon where ThoiGianLap>='{0}' and ThoiGianLap<='{1}'", daybegin, dayend);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
        
       public static bool Xoa_Tk_cthd_khoangngay(string daybegin, string dayend)
        {
            try
            {
                string str = string.Format("DELETE FROM ChiTietHoaDon where NgayTT>='{0}' and NgayTT<='{1}'", daybegin, dayend);
                SqlCommand com = new SqlCommand(str, Coso.con);
                com.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
       }
       public static bool Xoa_Tk_cthd_SoHD(string sohd)
       {
           try
           {
               string str = string.Format("DELETE FROM ChiTietHoaDon where SoHD='{0}'",sohd);
               SqlCommand com = new SqlCommand(str, Coso.con);
               com.ExecuteNonQuery();
               return true;
           }
           catch
           {
               return false;
           }
       }
       public static bool Xoa_Tk_hd_SoHD(string sohd)
       {
           try
           {
               string str = string.Format("DELETE FROM HoaDon where SoHD='{0}'", sohd);
               SqlCommand com = new SqlCommand(str, Coso.con);
               com.ExecuteNonQuery();
               return true;
           }
           catch
           {
               return false;
           }
       }
       public static DataTable Tke_cthd(string ma)
       {
           try
           {
               string sql = "SELECT * from ChiTietHoaDon where SoHD='"+ma+"'";
               SqlDataAdapter adap = new SqlDataAdapter(sql, Coso.con);
               DataTable tb = new DataTable();
               adap.Fill(tb);
               return tb;
           }
           catch
           {
               return null;
           }
       }
    }
}
